<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="120px">
      <el-form-item label="物流公司名称" prop="companyName">
        <el-input
          v-model="queryParams.companyName"
          placeholder="请输入物流公司名称"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
        <el-button
          type="primary"
          @click="handleAdd"
          v-hasPermi="['manage:logisticsdelivery:add']"
        >新增数据</el-button>
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['manage:logisticsdelivery:export']"
        >导出数据</el-button>

      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="logisticsdeliveryList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" width="50" prop="id" />
      <el-table-column label="物流公司名称" align="center" width="150" prop="companyName" />
      <el-table-column label="联系电话" align="center" prop="contactPhone" />
      <el-table-column label="服务范围" align="center" width="100" prop="serviceArea" />
      <el-table-column label="官方网址" align="center" prop="officialWebsite">
        <template #default="scope">
          <!-- 移除 href 属性，直接使用 @click 事件 -->
          <span class="official-website-link" @click="openOfficialWebsite(scope.row.officialWebsite)">
            {{ scope.row.officialWebsite }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remarks" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" @click="getLogisticsdeliveryInfo(scope.row)" v-hasPermi="['manage:logisticsdelivery:list']">查看价格详情</el-button>
          <el-button link type="primary" @click="handleUpdate(scope.row)" v-hasPermi="['manage:logisticsdelivery:edit']">修改</el-button>
          <el-button link type="primary" @click="handleDelete(scope.row)" v-hasPermi="['manage:logisticsdelivery:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加或修改物流公司配送信息对话框 -->
    <el-dialog :title="title" v-model="open" width="500px" append-to-body>
  <el-form ref="logisticsdeliveryRef" :model="form" :rules="rules" label-width="130px">
    <el-form-item label="物流公司名称" prop="companyName">
      <el-input v-model="form.companyName" placeholder="请输入物流公司名称" />
    </el-form-item>
    <el-form-item label="联系电话" prop="contactPhone">
      <el-input v-model="form.contactPhone" placeholder="请输入联系电话" />
    </el-form-item>
    <el-form-item label="服务范围" prop="serviceArea">
      <el-input v-model="form.serviceArea" type="textarea" placeholder="请输入内容" />
    </el-form-item>
    <el-form-item label="官方网址" prop="officialWebsite">
      <el-input v-model="form.officialWebsite" placeholder="请输入官方网址" />
    </el-form-item>

    <!-- 使用栅格系统来分两列显示 -->
    <el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="广西首重1kg/元" prop="gxFirstweight">
          <el-input v-model="form.gxFirstweight" placeholder="" />
        </el-form-item>
        <el-form-item label="广东首重1kg/元" prop="gdFirstweight">
          <el-input v-model="form.gdFirstweight" placeholder="" />
        </el-form-item>
        <el-form-item label="江浙沪首重1kg/元" prop="jzFirstweight">
          <el-input v-model="form.jzFirstweight" placeholder="" />
        </el-form-item>
        <el-form-item label="安徽首重1kg/元" prop="ahFirstweight">
          <el-input v-model="form.ahFirstweight" placeholder="" />
        </el-form-item>
        <el-form-item label="湖北首重1kg/元" prop="hbFirstweight">
          <el-input v-model="form.hbFirstweight" placeholder="" />
        </el-form-item>
        <el-form-item label="湖南首重1kg/元" prop="hnFirstweight">
          <el-input v-model="form.hnFirstweight" placeholder="" />
        </el-form-item>
        <el-form-item label="北京首重1kg/元" prop="bjFirstweight">
          <el-input v-model="form.bjFirstweight" placeholder="" />
        </el-form-item>
        <el-form-item label="天津首重1kg/元" prop="tjFirstweight">
          <el-input v-model="form.tjFirstweight" placeholder="" />
        </el-form-item>
        <el-form-item label="江西首重1kg/元" prop="jxFirstweight">
          <el-input v-model="form.jxFirstweight" placeholder="" />
        </el-form-item>
        <el-form-item label="福建首重1kg/元" prop="fjFirstweight">
          <el-input v-model="form.fjFirstweight" placeholder="" />
        </el-form-item>
        <el-form-item label="河北首重1kg/元" prop="hebFirstweight">
          <el-input v-model="form.hebFirstweight" placeholder="" />
        </el-form-item>
        <el-form-item label="河南首重1kg/元" prop="henFirstweight">
          <el-input v-model="form.henFirstweight" placeholder="" />
        </el-form-item>
        <el-form-item label="重庆首重1kg/元" prop="cqFirstweight">
          <el-input v-model="form.cqFirstweight" placeholder="" />
        </el-form-item>
        <el-form-item label="海南首重1kg/元" prop="hiFirstweight">
          <el-input v-model="form.hiFirstweight" placeholder="" />
        </el-form-item>
        <el-form-item label="山东首重1kg/元" prop="sdFirstweight">
          <el-input v-model="form.sdFirstweight" placeholder="" />
        </el-form-item>
        <el-form-item label="云南首重1kg/元" prop="ynFirstweight">
          <el-input v-model="form.ynFirstweight" placeholder="" />
        </el-form-item>
        <el-form-item label="贵州首重1kg/元" prop="gzFirstweight">
          <el-input v-model="form.gzFirstweight" placeholder="" />
        </el-form-item>
        <el-form-item label="四川首重1kg/元" prop="scFirstweight">
          <el-input v-model="form.scFirstweight" placeholder="" />
        </el-form-item>
        <el-form-item label="陕西首重1kg/元" prop="snFirstweight">
          <el-input v-model="form.snFirstweight" placeholder="" />
        </el-form-item>
        <el-form-item label="山西首重1kg/元" prop="sxFirstweight">
          <el-input v-model="form.sxFirstweight" placeholder="" />
        </el-form-item>
        <el-form-item label="黑吉辽首重1kg/元" prop="hjlFirstweight">
          <el-input v-model="form.hjlFirstweight" placeholder="" />
        </el-form-item>
        <el-form-item label="内蒙古首重1kg/元" prop="nmFirstweight">
          <el-input v-model="form.nmFirstweight" placeholder="" />
        </el-form-item>
        <el-form-item label="青甘宁首重1kg/元" prop="qgnFirstweight">
          <el-input v-model="form.qgnFirstweight" placeholder="" />
        </el-form-item>
        <el-form-item label="西藏首重1kg/元" prop="xzFirstweight">
          <el-input v-model="form.xzFirstweight" placeholder="" />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="广西续重1kg/元" prop="gxAdditionalweight">
          <el-input v-model="form.gxAdditionalweight" placeholder="" />
        </el-form-item>
        <el-form-item label="广东续重1kg/元" prop="gdAdditionalweight">
          <el-input v-model="form.gdAdditionalweight" placeholder="" />
        </el-form-item>
        <el-form-item label="江浙沪续重1kg/元" prop="jzAdditionalweight">
          <el-input v-model="form.jzAdditionalweight" placeholder="" />
        </el-form-item>
        <el-form-item label="安徽续重1kg/元" prop="ahAdditionalweight">
          <el-input v-model="form.ahAdditionalweight" placeholder="" />
        </el-form-item>
        <el-form-item label="湖北续重1kg/元" prop="hbAdditionalweight">
          <el-input v-model="form.hbAdditionalweight" placeholder="" />
        </el-form-item>
        <el-form-item label="湖南续重1kg/元" prop="hnAdditionalweight">
          <el-input v-model="form.hnAdditionalweight" placeholder="" />
        </el-form-item>
        <el-form-item label="北京续重1kg/元" prop="bjAdditionalweight">
          <el-input v-model="form.bjAdditionalweight" placeholder="" />
        </el-form-item>
        <el-form-item label="天津续重1kg/元" prop="tjAdditionalweight">
          <el-input v-model="form.tjAdditionalweight" placeholder="" />
        </el-form-item>
        <el-form-item label="江西续重1kg/元" prop="jxAdditionalweight">
          <el-input v-model="form.jxAdditionalweight" placeholder="" />
        </el-form-item>
        <el-form-item label="福建续重1kg/元" prop="fjAdditionalweight">
          <el-input v-model="form.fjAdditionalweight" placeholder="" />
        </el-form-item>
        <el-form-item label="河北续重1kg/元" prop="hebAdditionalweight">
          <el-input v-model="form.hebAdditionalweight" placeholder="" />
        </el-form-item>
        <el-form-item label="河南续重1kg/元" prop="henAdditionalweight">
          <el-input v-model="form.henAdditionalweight" placeholder="" />
        </el-form-item>
        <el-form-item label="重庆续重1kg/元" prop="cqAdditionalweight">
          <el-input v-model="form.cqAdditionalweight" placeholder="" />
        </el-form-item>
        <el-form-item label="海南续重1kg/元" prop="hiAdditionalweight">
          <el-input v-model="form.hiAdditionalweight" placeholder="" />
        </el-form-item>
        <el-form-item label="山东续重1kg/元" prop="sdAdditionalweight">
          <el-input v-model="form.sdAdditionalweight" placeholder="" />
        </el-form-item>
        <el-form-item label="云南续重1kg/元" prop="ynAdditionalweight">
          <el-input v-model="form.ynAdditionalweight" placeholder="" />
        </el-form-item>
        <el-form-item label="贵州续重1kg/元" prop="gzAdditionalweight">
          <el-input v-model="form.gzAdditionalweight" placeholder="" />
        </el-form-item>
        <el-form-item label="四川续重1kg/元" prop="scAdditionalweight">
          <el-input v-model="form.scAdditionalweight" placeholder="" />
        </el-form-item>
        <el-form-item label="陕西续重1kg/元" prop="snAdditionalweight">
          <el-input v-model="form.snAdditionalweight" placeholder="" />
        </el-form-item>
        <el-form-item label="山西续重1kg/元" prop="sxAdditionalweight">
          <el-input v-model="form.sxAdditionalweight" placeholder="" />
        </el-form-item>
        <el-form-item label="黑吉辽续重1kg/元" prop="hjlAdditionalweight">
          <el-input v-model="form.hjlAdditionalweight" placeholder="" />
        </el-form-item>
        <el-form-item label="内蒙古续重1kg/元" prop="nmAdditionalweight">
          <el-input v-model="form.nmAdditionalweight" placeholder="" />
        </el-form-item>
        <el-form-item label="青甘宁续重1kg/元" prop="qgnAdditionalweight">
          <el-input v-model="form.qgnAdditionalweight" placeholder="" />
        </el-form-item>
        <el-form-item label="西藏续重1kg/元" prop="xzAdditionalweight">
          <el-input v-model="form.xzAdditionalweight" placeholder="" />
        </el-form-item>
      </el-col>
    </el-row>

    <el-form-item label="备注" prop="remarks">
      <el-input v-model="form.remarks" type="textarea" placeholder="请输入内容" />
    </el-form-item>
  </el-form>
  <template #footer>
    <div class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </template>
</el-dialog>

<!--查看物流价格详情对话框 -->
<el-dialog title="物流价格详情" v-model="logisticsdeliveryInfoOpen" width="650px" append-to-body align="center">
  <el-table :data="[form]" style="width: 100%">
    <el-table-column prop="gxFirstweight" label="广西首重 1kg/元" width="150" align="center" />
  <el-table-column prop="gxAdditionalweight" label="广西续重 1kg/元" width="150" align="center" />
  <el-table-column prop="gdFirstweight" label="广东首重 1kg/元" width="150" align="center" />
  <el-table-column prop="gdAdditionalweight" label="广东续重 1kg/元" width="150" align="center" />
  </el-table>
  
  <el-table :data="[form]" style="width: 100%">
    <el-table-column prop="jzFirstweight" label="江浙沪首重 1kg/元" width="150" align="center" />
  <el-table-column prop="jzAdditionalweight" label="江浙沪首重 1kg/元" width="150" align="center" />
  <el-table-column prop="ahFirstweight" label="安徽首重 1kg/元" width="150" align="center" />
  <el-table-column prop="ahAdditionalweight" label="安徽续重 1kg/元" width="150" align="center" />
  </el-table>
  
  <el-table :data="[form]" style="width: 100%">
    <el-table-column prop="hbFirstweight" label="湖北首重 1kg/元" width="150" align="center" />
    <el-table-column prop="hbAdditionalweight" label="湖北续重 1kg/元" width="150" align="center" />
    <el-table-column prop="hnFirstweight" label="湖南首重 1kg/元" width="150" align="center" />
    <el-table-column prop="hnAdditionalweight" label="湖南续重 1kg/元" width="150" align="center" />
  </el-table>
  
  <el-table :data="[form]" style="width: 100%">
    <el-table-column prop="bjFirstweight" label="北京首重 1kg/元" width="150" align="center" />
    <el-table-column prop="bjAdditionalweight" label="北京续重 1kg/元" width="150" align="center" />
    <el-table-column prop="tjFirstweight" label="天津首重 1kg/元" width="150" align="center" />
  <el-table-column prop="tjAdditionalweight" label="天津续重 1kg/元" width="150" align="center" />
  </el-table>
  
  <el-table :data="[form]" style="width: 100%">
    <el-table-column prop="jxFirstweight" label="江西首重 1kg/元" width="150" align="center" />
    <el-table-column prop="jxAdditionalweight" label="江西续重 1kg/元" width="150" align="center" />
    <el-table-column prop="fjFirstweight" label="福建首重 1kg/元" width="150" align="center" />
  <el-table-column prop="fjAdditionalweight" label="福建续重 1kg/元" width="150" align="center" />
  </el-table>

  <el-table :data="[form]" style="width: 100%">
    <el-table-column prop="hebFirstweight" label="河北首重 1kg/元" width="150" align="center" />
    <el-table-column prop="hebAdditionalweight" label="河北重 1kg/元" width="150" align="center" />
    <el-table-column prop="henFirstweight" label="河南首重 1kg/元" width="150" align="center" />
  <el-table-column prop="henAdditionalweight" label="河南续重 1kg/元" width="150" align="center" />
  </el-table>

  <el-table :data="[form]" style="width: 100%">
    <el-table-column prop="cqFirstweight" label="重庆首重 1kg/元" width="150" align="center" />
    <el-table-column prop="cqAdditionalweight" label="重庆续重 1kg/元" width="150" align="center" />
    <el-table-column prop="hiFirstweight" label="海南首重 1kg/元" width="150" align="center" />
  <el-table-column prop="hiAdditionalweight" label="海南续重 1kg/元" width="150" align="center" />
  </el-table>

  <el-table :data="[form]" style="width: 100%">
    <el-table-column prop="sdFirstweight" label="山东首重 1kg/元" width="150" align="center" />
    <el-table-column prop="sdAdditionalweight" label="山东续重 1kg/元" width="150" align="center" />
    <el-table-column prop="ynFirstweight" label="云南首重 1kg/元" width="150" align="center" />
  <el-table-column prop="ynAdditionalweight" label="云南续重 1kg/元" width="150" align="center" />
  </el-table>

  <el-table :data="[form]" style="width: 100%">
    <el-table-column prop="gzFirstweight" label="贵州首重 1kg/元" width="150" align="center" />
  <el-table-column prop="gzAdditionalweight" label="贵州续重 1kg/元" width="150" align="center" />
  <el-table-column prop="scFirstweight" label="四川首重 1kg/元" width="150" align="center" />
  <el-table-column prop="scAdditionalweight" label="四川续重 1kg/元" width="150" align="center" />
  </el-table>
  
  <el-table :data="[form]" style="width: 100%">
    <el-table-column prop="snFirstweight" label="陕西首重 1kg/元" width="150" align="center" />
    <el-table-column prop="snAdditionalweight" label="陕西续重 1kg/元" width="150" align="center" />
    <el-table-column prop="sxFirstweight" label="山西首重 1kg/元" width="150" align="center" />
  <el-table-column prop="sxAdditionalweight" label="山西续重 1kg/元" width="150" align="center" />
  </el-table>
  
  <el-table :data="[form]" style="width: 100%">
    <el-table-column prop="hjlFirstweight" label="黑吉辽首重 1kg/元" width="150" align="center" />
    <el-table-column prop="hjlAdditionalweight" label="黑吉辽续重 1kg/元" width="150" align="center" />
    <el-table-column prop="nmFirstweight" label="内蒙古首重 1kg/元" width="150" align="center" />
    <el-table-column prop="nmAdditionalweight" label="内蒙古续重 1kg/元" width="150" align="center" />
  </el-table>
  
  <el-table :data="[form]" style="width: 100%">
    <el-table-column prop="qgnFirstweight" label="青甘宁首重 1kg/元" width="150" align="center" />
    <el-table-column prop="qgnAdditionalweight" label="青甘宁续重 1kg/元" width="150" align="center" />
    <el-table-column prop="xzFirstweight" label="西藏首重 1kg/元" width="150" align="center" />
    <el-table-column prop="xzAdditionalweight" label="西藏续重 1kg/元" width="150" align="center" />
  </el-table>
 
</el-dialog>
  </div>
</template>

<script setup name="Logisticsdelivery">
import { listLogisticsdelivery, getLogisticsdelivery, delLogisticsdelivery, addLogisticsdelivery, updateLogisticsdelivery } from "@/api/manage/logisticsdelivery";

const { proxy } = getCurrentInstance();

const logisticsdeliveryList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    companyName: null,
  },
  rules: {
    companyName: [
      { required: true, message: "物流公司名称不能为空", trigger: "blur" }
    ],
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询物流公司配送信息列表 */
function getList() {
  loading.value = true;
  listLogisticsdelivery(queryParams.value).then(response => {
    logisticsdeliveryList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    companyName: null,
    contactPhone: null,
    serviceArea: null,
    officialWebsite: null,
    gxFirstweight: null,
    gxAdditionalweight: null,
    gdFirstweight: null,
    gdAdditionalweight: null,
    jzFirstweight: null,
    jzAdditionalweight: null,
    ahFirstweight: null,
    ahAdditionalweight: null,
    hbFirstweight: null,
    hbAdditionalweight: null,
    hnFirstweight: null,
    hnAdditionalweight: null,
    bjFirstweight: null,
    bjAdditionalweight: null,
    tjFirstweight: null,
    tjAdditionalweight: null,
    jxFirstweight: null,
    jxAdditionalweight: null,
    fjFirstweight: null,
    fjAdditionalweight: null,
    hebFirstweight: null,
    hebAdditionalweight: null,
    henFirstweight: null,
    henAdditionalweight: null,
    cqFirstweight: null,
    cqAdditionalweight: null,
    hiFirstweight: null,
    hiAdditionalweight: null,
    sdFirstweight: null,
    sdAdditionalweight: null,
    ynFirstweight: null,
    ynAdditionalweight: null,
    gzFirstweight: null,
    gzAdditionalweight: null,
    scFirstweight: null,
    scAdditionalweight: null,
    snFirstweight: null,
    snAdditionalweight: null,
    sxFirstweight: null,
    sxAdditionalweight: null,
    hjlFirstweight: null,
    hjlAdditionalweight: null,
    nmFirstweight: null,
    nmAdditionalweight: null,
    qgnFirstweight: null,
    qgnAdditionalweight: null,
    xzFirstweight: null,
    xzAdditionalweight: null,
    createdAt: null,
    updatedAt: null,
    createdBy: null,
    updatedBy: null,
    remarks: null
  };
  proxy.resetForm("logisticsdeliveryRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}
/**打开新标签页实现跳转*/
/** 打开官方网址 */
function openOfficialWebsite(url) {
  // 确保 URL 是完整的
  if (!url.startsWith('http://') && !url.startsWith('https://')) {
    url = 'http://' + url; // 如果不是 http 或 https 开头，则加上 http://
  }
  window.open(url, '_blank');
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加物流公司配送信息";
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  const _id = row.id || ids.value
  getLogisticsdelivery(_id).then(response => {
    form.value = response.data;
    open.value = true;
    title.value = "修改物流公司配送信息";
  });
}
/**查看物流价格详情*/
const logisticsdeliveryInfoOpen=ref(false)
function getLogisticsdeliveryInfo(row) {
  reset();
  const _id = row.id
  getLogisticsdelivery(_id).then(response => {
    form.value = response.data;
    logisticsdeliveryInfoOpen.value=true;

  });
}
/** 提交按钮 */
function submitForm() {
  proxy.$refs["logisticsdeliveryRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateLogisticsdelivery(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addLogisticsdelivery(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value;
  proxy.$modal.confirm('是否确认删除物流公司配送信息编号为"' + _ids + '"的数据项？').then(function() {
    return delLogisticsdelivery(_ids);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {});
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('manage/logisticsdelivery/export', {
    ...queryParams.value
  }, `logisticsdelivery_${new Date().getTime()}.xlsx`)
}

getList();
</script>

<style scoped>
.official-website-link {
  color: blue; /* 设置链接颜色为蓝色 */
  text-decoration: none; /* 去掉下划线 */
  cursor: pointer; /* 鼠标悬停时显示手型指针 */
}
.official-website-link:hover {
  text-decoration: underline; /* 鼠标悬停时显示下划线 */
}
</style>